package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import business.SeanceBL;

public class PeriodeServiceUI extends JPanel {
	private int idService;
	private int idPeriode;
	
	private AbstractPopupController popupController = new AbstractPopupController() {
		public JPopupMenu makePopup(int x, int y) {
			return new Popup();
		}
	};

	public PeriodeServiceUI(int idServ, int idPer) {
		idService = idServ;
		idPeriode = idPer;
		this.setLayout(new GridLayout(1,0));
		this.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK));
		
		this.addMouseListener(popupController);
	}
	
/*	public PeriodeServiceUI(SeanceUI cours) {
		this();
		add(cours);
	}
*/	
	public void add(SeanceUI cours)
	{
		super.add(cours);
		this.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.BLACK));
	}
	
	private class Popup extends JPopupMenu implements ActionListener {
		JMenuItem ajouter = new JMenuItem("Ajouter");
		
		public Popup() {
			ajouter.addActionListener(this);
			add(ajouter);
		}
		
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == ajouter) {
				FrameAjoutSeance frameAjout = new FrameAjoutSeance(null, -1, idService, idPeriode, false);
				frameAjout.setVisible(true);
			}

		}
			
		
	}

}
